﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using Tao.FreeGlut;
using TWiStEr.Math;

namespace TWiStEr.OpenGL.Utilities {
	using Math = System.Math;
	public partial class Camera {
		// rotates the target n radians along the specific axis(es)
		//void rotateView(double x, double y, double z) {
		//    Vector v = View - Position;
		//    if (x != 0) {
		//        View.Z = Position.Z + Math.Sin(x) * v.Y + Math.Cos(x) * v.Z;
		//        View.Y = Position.Y + Math.Cos(x) * v.Y - Math.Sin(x) * v.Z;
		//    }
		//    if (y != 0) {
		//        View.Z = Position.Z + Math.Sin(y) * v.X + Math.Cos(y) * v.Z;
		//        View.X = Position.X + Math.Cos(y) * v.X - Math.Sin(y) * v.Z;
		//    }
		//    if (z != 0) {
		//        View.X = Position.X + Math.Sin(z) * v.Y + Math.Cos(z) * v.X;
		//        View.Y = Position.Y + Math.Cos(z) * v.Y - Math.Sin(z) * v.X;
		//    }
		//    IsChanged = true;
		//}
		// rotates the target n degrees along the specific axis(es)
		/*
		rotate(a, x, y, z):
			a, 1, 0, 0:			a, 0, 1, 0:			a, 0, 0, 1:
			1	0	0	0		+c	0	+s	0		+c	-s	0	0
			0	+c	-s	0		0	1	0	0		+s	+c	0	0
			0	+s	+c	0		-s	0	+c	0		0	0	1	0
			0	0	0	1		0	0	0	1		0	0	0	1
		*/

		void rotateViewd(double x, double y, double z) {
			Vector v = View - Position;
			double rads;
			if (x != 0) {
				rads = x * Math.PI / 180.0;
				View.Z = Position.Z + Math.Sin(rads) * v.Y + Math.Cos(rads) * v.Z;
				View.Y = Position.Y + Math.Cos(rads) * v.Y - Math.Sin(rads) * v.Z;
			}
			if (y != 0) {
				rads = y * Math.PI / 180.0;
				View.Z = Position.Z + Math.Sin(rads) * v.X + Math.Cos(rads) * v.Z;
				View.X = Position.X + Math.Cos(rads) * v.X - Math.Sin(rads) * v.Z;
			}
			if (z != 0) {
				rads = z * Math.PI / 180.0;
				View.X = Position.X + Math.Sin(rads) * v.Y + Math.Cos(rads) * v.X;
				View.Y = Position.Y + Math.Cos(rads) * v.Y - Math.Sin(rads) * v.X;
			}
			IsChanged = true;
		}
		//// rotates the camera n radians along the specific axis(es)
		//void rotatePos(double x, double y, double z) {
		//    Vector v = Position - View;
		//    if (x != 0) {
		//        Position.Z = View.Z + Math.Sin(x) * v.Y + Math.Cos(x) * v.Z;
		//        Position.Y = View.Y + Math.Cos(x) * v.Y - Math.Sin(x) * v.Z;
		//    }
		//    if (y != 0) {
		//        Position.Z = View.Z + Math.Sin(y) * v.X + Math.Cos(y) * v.Z;
		//        Position.X = View.X + Math.Cos(y) * v.X - Math.Sin(y) * v.Z;
		//    }
		//    if (z != 0) {
		//        Position.X = View.X + Math.Sin(z) * v.Y + Math.Cos(z) * v.X;
		//        Position.Y = View.Y + Math.Cos(z) * v.Y - Math.Sin(z) * v.X;
		//    }
		//    IsChanged = true;
		//}
		// rotates the camera n degrees along the specific axis(es)
		void rotatePosd(double x, double y, double z) {
			Vector v = Position - View;
			double rads;
			if (x != 0) {
				rads = x * Math.PI / 180.0;
				Position.Z = View.Z + Math.Sin(x) * v.Y + Math.Cos(x) * v.Z;
				Position.Y = View.Y + Math.Cos(x) * v.Y - Math.Sin(x) * v.Z;
			}
			if (y != 0) {
				rads = y * Math.PI / 180.0;
				Position.Z = View.Z + Math.Sin(y) * v.X + Math.Cos(y) * v.Z;
				Position.X = View.X + Math.Cos(y) * v.X - Math.Sin(y) * v.Z;
			}
			if (z != 0) {
				rads = z * Math.PI / 180.0;
				Position.X = View.X + Math.Sin(z) * v.Y + Math.Cos(z) * v.X;
				Position.Y = View.Y + Math.Cos(z) * v.Y - Math.Sin(z) * v.X;
			}
			IsChanged = true;
		}

		//int getWindowWidth() { return windowWidth; }
		//int getWindowHeight() { return windowHeight; }
		//void setPos(Vector newPos) { Position = newPos; IsChanged = true; }
		//void setView(Vector newView) { View = newView; IsChanged = true; }
		//void setUp(Vector newUp) { Up = newUp; IsChanged = true; }
		//void setFoV(double fov) { if (fov > 0 && fov < 360) this.FOV = fov; }
		//double getFoV() { return FOV; }
	}
}
